﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows;
using System.ComponentModel;

namespace produccion.vistamodelo
{
   public class VMbuscarGeneral:ViewModelBase
    {

        #region 
        public VMbuscarGeneral(List<VMlistaGenerica> _listaFiltrar) 
        {
            gridBuscar = new VMgridBuscar(_listaFiltrar);
            gridBuscar.PropertyChanged += OnGbPropertyChanged;
        }

        public VMbuscarGeneral()
        {
           

        }
        #endregion

        #region public interfaces

        RelayCommand _cmdAceptar;
        public ICommand cmdAceptar
        {
            get
            {

                if (_cmdAceptar == null)
                {
                    _cmdAceptar = new RelayCommand(r => Aceptar());
                }
                return _cmdAceptar;
            }
        }

        RelayCommand _cmdSalir;
        public ICommand cmdSalir
        {
            get
            {

                if (_cmdSalir == null)
                {
                    _cmdSalir = new RelayCommand(r => Salir());
                }
                return _cmdSalir;
            }
        }

        private bool _IsOpen = false;
        public bool IsOpen
        {
            get { return _IsOpen; }
            set
            {
                _IsOpen = value;
                base.OnPropertyChanged("IsOpen");
            }
        }

        private VMgridBuscar _gridBuscar;
        public VMgridBuscar gridBuscar
        {
            get { return _gridBuscar; }
            set
            {
                _gridBuscar = value;
                base.OnPropertyChanged("gridBuscar");
            }
        }

        #endregion

        #region methods

        void OnGbPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Click") {
                Aceptar();
            }
        }

        public void Aceptar()
        {
            try
            {
                IsOpen = false;
                gridBuscar.selLista = null;
                gridBuscar.quitarFiltros();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        public void Salir()
        {
            try
            {
                gridBuscar.selLista = null;
                IsOpen = false;
                gridBuscar.quitarFiltros();
            }
            catch (Exception ex) { throw ex; }
        }
        #endregion

    }
}
